package loja.teste;

import loja.util.HibernateUtil;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;
import org.junit.AfterClass;
import org.junit.BeforeClass;

public abstract class TestBase {

	protected static Session session;
	protected static Transaction transaction;

	@BeforeClass
	public static void abreConexao() {

		session = HibernateUtil.getSessionFactory().getCurrentSession();
		transaction = session.beginTransaction();

	}

	@AfterClass
	public static void fechaConexao() {
		try {
			transaction.commit();
		} catch (Throwable t) {
			System.out.println("deu erro no commit da conexao : "
					+ t.getMessage());
		} finally {
			try {
				if (session.isOpen())
					session.close();
			} catch (Exception e) {
				System.out.println("deu erro no fechamento da conexao : "
						+ e.getMessage());
			}
		}

	}

}
